<?php

namespace App\Models;



use Illuminate\Database\Eloquent\SoftDeletes;

class Appoint extends Base
{
    const STATUS_WAIT_EDIT_PRICE = 0;
    const STATUS_WAIT_PAY =1;
    const STATUS_PAID = 2;
    const STATUS_WAIT_REMARK = 3;
    const STATUS_REMARK_ED = 4;
    const STATUS_CANCEL = 5;

    const PAY_TYPE_OFFLINE  = 3;
    const PAY_TYPE_WX = 2;

    use SoftDeletes;

    protected $appends = ['amount_yuan'];

    public function service() {
        return $this->belongsTo(ServiceSnapshot::class, 'service_snopshot_id');
    }

    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function comment() {
        return $this->hasOne(OrderComment::class, 'appoint_id');
    }


    public static function getPaidAmount() {
        $amount = Appoint::where('status', Appoint::STATUS_PAID)->sum('amount');
        return format_yuan($amount);
    }

    public function getAmountYuanAttribute() {
        return format_yuan($this->amount);
    }
}
